package com.example.customeview;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.MyViewHolder> {

    private List<String> mlist;
    private Context mContext;

    public MyRecyclerViewAdapter(List<String> list,Context context) {
        mlist = list;
        mContext = context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.recycler_item,
                parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
        holder.myText.setText(mlist.get(position));
        holder.myText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NotificationUtil notificationUtil = new NotificationUtil(mContext, 1);
                notificationUtil.sendNotification("通知","第"+position+"被点击了"
                ,notificationUtil.createPendingIntent((Activity) mContext));
            }
        });
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView myText;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
           myText = itemView.findViewById(R.id.my_custome_text);

        }
    }
}
